package com.edu.nju.nationalflag;

import java.util.ArrayList;



import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ShowSelectedImageAdapter extends BaseAdapter{
	
	SearchActivity activity;// = new MainActivity();
	private ArrayList<Integer> filterresult;
	private Context mContext;
	ImageView imageView;
	private ArrayList<Integer> imageI = new ArrayList<Integer>();
	
	private Integer[] colorImageIds = new Integer[]{
			R.drawable.color_black,R.drawable.color_blue,R.drawable.color_brown,R.drawable.color_green,
			R.drawable.color_orange,R.drawable.color_purple,R.drawable.color_red,R.drawable.color_white,
			R.drawable.color_yellow
	};
	
	
	public ShowSelectedImageAdapter(Context c, SearchActivity at, ArrayList<Integer> al) {
		mContext = c;
		activity = at;
		filterresult = al;
		int j = 0;
		for (int i = 0; i < filterresult.size(); i++) {
			if (filterresult.get(i) != 0) {
				imageI.add(j,i);
				j++;
			}
		}
	}
	
	@Override
	public int getCount() {
		return imageI.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			imageView = new ImageView(mContext);
			imageView.setClickable(true);
			imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
			imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
		} else {
			imageView = (ImageView) convertView;
		}

		imageView.setBackgroundResource(colorImageIds[imageI.get(position)]);
		return imageView;
	}
}
